package com.controller;

import com.annotation.IgnoreAuth;
import com.entity.PointGoods;
import com.entity.UserGoods;
import com.entity.ZhiyuanzheEntity;
import com.service.PointGoodsService;
import com.service.UserGoodsService;
import com.service.ZhiyuanzheService;
import com.service.impl.UserGoodsServiceImpl;
import com.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags= "商品和用户信息记录")
@RestController
@RequestMapping("/userGoods")
public class UserGoodsController {

    @Autowired
    private UserGoodsService userGoodsService;

    @Autowired
    private PointGoodsService pointGoodsService;


    @ApiOperation(value = "根据用户id查询商品信息")
//    @ResponseBody
    @RequestMapping("/findByUserId")
    public R findByUserId(Integer userId){
        return R.ok().put("data", pointGoodsService.findByUserId(userId));
    }


    @ApiOperation(value = "用户新增商品")
    @RequestMapping("insert")
    public R insert(@RequestBody UserGoods userGoods){
        if (userGoodsService.insert(userGoods)){
            return R.ok().put("data","兑换物品成功");
        }else {
            return R.error().put("data","兑换物品失败,积分不足！");
        }
    }

}
